package com.enhe.gck.fg;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.enhe.gck.CarbonBaseConstant;
import com.enhe.gck.CarbonEnumKeyValue;
import com.enhe.gck.CarbonRelationType;
import com.enhe.gck.communal.PublicConstant;
import com.enhe.gck.communal.PublicEnum;
import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.communal.PublicReturn;
import com.enhe.gck.item.*;
import com.enhe.gck.pojo.*;
import com.enhe.gck.service.impl.ConfigService;
import com.enhe.gck.service.impl.GckFrontService;
import com.enhe.gck.service.impl.VehicleOrderService;
import com.kuangkie.carbon.common.IntegrationMsg;
import com.kuangkie.carbon.common.RemoveRecordInfo;
import com.kuangkie.carbon.fg.*;
import com.kuangkie.carbon.fg.ops.ProRecordOpsBuilder;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.FGRecord;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;

import static com.enhe.gck.CarbonEnumKeyValue.参数配置_类型_批号异常校验_phycxy;
import static com.enhe.gck.CarbonEnumKeyValue.批次类型_水泥批次_snpc;

@Slf4j
@Repository(value = "hwane16720366042330866425862")
public class WeighHWANE16720BNB implements SecondRoundImproveFuncGroup, RemoveFuncGroup {

	@Resource
	private PouringOrderHWANE18490BNB pouringOrderHWANE18490BNB;
	@Resource
	private VehicleOrderService vehicleOrderService;
	@Resource
	private GckFrontService gckFrontService;
	@Resource
	private ConfigService configService;

	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
							  ImproveResultFactory improveResultFactory) {
		WeighOther weighOther =proRecord.getBean(WeighOther.class);

		if(String.valueOf(CarbonEnumKeyValue.操作命令_修改地磅称重图片_xgdbcztp).equals(weighOther.getCommand())){

		}else {
			if(String.valueOf(CarbonEnumKeyValue.操作命令_过磅记录_手工过磅_gbjlsggb).equals(weighOther.getCommand())){
				if(weighOther.getFrequency()!=null){
					if(!syncOrder(weighOther,improveResultFactory)){
						return;
					}
					if (1 == weighOther.getFrequency() && weighOther.getOrderNumber().startsWith(PublicEnum.OrderHeader.OR.getCode())) {
						if (batchPackageDateCheck(improveResultFactory, weighOther)) return;
					}
				}else {
					PublicMethod.returnMessage(improveResultFactory, PublicReturn.ORDER_10);
				}
			}

			if(proRecord.isNew()){
				OperationLogHWANE21797BNB.save(improveResultFactory,2,1,proRecord.getRecordCode());
				String order=PublicMethod.getOrderCodeWE();
				ProRecordOpsBuilder setData=improveResultFactory.getCurrentProRecordOpsBuilder();
				setData.putAttribute(WeighHWANE16720Item.基本属性组_过磅号, order);
				Boolean isOk=proRecord.getBoolean(WeighHWANE16720Item.基本属性组_是否正常);
				if(isOk!=null){
					if(!isOk) {
						log.info("异常信息:{}",proRecord.getRecordCode());
						improveResultFactory.getProRecordOpsBuilder(CarbonBaseConstant.过磅异常_gbyc)
								.addRelation(CarbonRelationType.RR_过磅异常_过磅信息_过磅信息, proRecord.getRecordCode())
								.putAttribute(WeighErrHWANE16734Item.基本属性组_异常原因, proRecord.getString(WeighHWANE16720Item.基本属性组_原因))
								.putAttribute(WeighErrHWANE16734Item.基本属性组_车牌号, proRecord.getString(WeighHWANE16720Item.基本属性组_车牌号))
								.putAttribute(WeighErrHWANE16734Item.基本属性组_是否处理, false);
					}else {
						log.info("正常信息:{}",proRecord.getRecordCode());
						if(!StrUtil.isBlank(weighOther.getOrderNumber())&& weighOther.getFrequency()!=null){
							FGRecord fRecord=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.过磅信息_gbxx).getProConJunctionFactory()
									.addEqual(WeighHWANE16720Item.基本属性组_订单号, weighOther.getOrderNumber())
									.addEqual(WeighHWANE16720Item.基本属性组_是否正常,true)
									.addEqual(WeighHWANE16720Item.基本属性组_过磅次数, weighOther.getFrequency())
									.goBack().queryARecord();
							if(fRecord!=null){
								PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_1);
							}
						}
					}
				}
			}else {
				boolean verifyActionable=VerifyActionable(weighOther,improveResultFactory,null);
				if(verifyActionable){
					if(updateWeigh(weighOther,improveResultFactory)){
						return;
					}
				}else {
					return;
				}
			}
		}
	}

	private boolean batchPackageDateCheck(ImproveResultFactory improveResultFactory, WeighOther weighOther) {
		// 手工过磅触发批次信息更新判断
		Optional<OrderCommon> currentOrderOptional = vehicleOrderService.getNoCompletedOrderByOrderNo(weighOther.getOrderNumber());
		if (!currentOrderOptional.isPresent()) {
			PublicMethod.returnMessage(improveResultFactory, PublicReturn.INVOICING_2);
			return true;
		}
		OrderCommon order = currentOrderOptional.get();
		// 这里只校验水泥批次
		boolean isCementBatch = Objects.equals(String.valueOf(批次类型_水泥批次_snpc), order.getBatchType());
		Optional<Config> batchCheckOptional = configService.getConfig(参数配置_类型_批号异常校验_phycxy);
		log.info("{}；是否为水泥批次：{}，批号异常校验：{}", "【手工过磅处理】", isCementBatch, batchCheckOptional);
		if (isCementBatch && batchCheckOptional.isPresent() && Objects.equals(batchCheckOptional.get().getValue(), "true")) {
			gckFrontService.saleOrderBatchPackageDateCheck("【手工过磅处理】", order);
		}
		return false;
	}

	private boolean syncOrder(WeighOther weighOther, ImproveResultFactory improveResultFactory){

		log.info("触发手工过磅:{}",JSON.toJSON(weighOther));
		improveResultFactory.getCurrentProRecordOpsBuilder()
				.putAttribute(WeighHWANE16720Item.基本属性组_净重,BigDecimal.ZERO);
		if(weighOther.getOrderNumber()==null){
			PublicMethod.returnMessage(improveResultFactory, PublicReturn.ORDER_10);
			return false;
		}
		WeighOther weighOther1 =getWeigh(weighOther.getOrderNumber(),1);
		WeighOther weighOther2 =getWeigh(weighOther.getOrderNumber(),2);

		Order order=null;
		SupplyOrder supplyOrder=null;
		PouringOrder pouringOrder=null;
		if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.OR.getCode())){
			order=PublicMethod.query(CarbonBaseConstant.订单记录_ddjl)
					.addEqual(OrderHWANE16677Item.基本属性组_单号, weighOther.getOrderNumber())
					.addEqual(OrderHWANE16677Item.基本属性组_是否作废,CarbonEnumKeyValue.是否_否_f)
					.addEqual(OrderHWANE16677Item.基本属性组_是否退货,CarbonEnumKeyValue.是否_否_f)
					.goBack().queryABean(Order.class);
			log.info("查询订单记录:{}",JSON.toJSON(order));
		}
		if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.SM.getCode())){
			supplyOrder=PublicMethod.query(CarbonBaseConstant.供货订单_ghdd)
					.addEqual(SupplyOrderHWANE16829Item.基本属性组_是否作废,CarbonEnumKeyValue.是否_否_f)
					.addEqual(SupplyOrderHWANE16829Item.基本属性组_是否退货,CarbonEnumKeyValue.是否_否_f)
					.addEqual(SupplyOrderHWANE16829Item.基本属性组_单号, weighOther.getOrderNumber())
					.goBack().queryABean(SupplyOrder.class);
			log.info("查询供货订单:{}",JSON.toJSON(supplyOrder));
		}
		if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.PM.getCode())){
			pouringOrder=PublicMethod.query(CarbonBaseConstant.倒料订单_dldd)
					.addEqual(PouringOrderHWANE18490Item.基本属性组_单号, weighOther.getOrderNumber())
					.addEqual(PouringOrderHWANE18490Item.基本属性组_是否作废,false)
					.goBack().queryABean(PouringOrder.class);
			log.info("查询倒料订单:{}",JSON.toJSON(pouringOrder));
		}
		String orderCode=null;
		if(order!=null){
			log.info("订单赋值:{}",order.getRecordCode());
			orderCode=order.getRecordCode();
		}
		if(supplyOrder!=null){
			log.info("订单供货:{}",supplyOrder.getRecordCode());
			orderCode=supplyOrder.getRecordCode();
		}
		if(pouringOrder!=null){
			log.info("订单倒料:{}",pouringOrder.getRecordCode());
			orderCode=pouringOrder.getRecordCode();
		}

		if(orderCode!=null){
			switch (weighOther.getFrequency()){
				case 1:
					log.info("一次过磅触发:{}",orderCode);
					if(weighOther1 !=null){
						PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_1);
						return false;
					}
					IntegrationMsg integrationMsg=null;
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.OR.getCode())){
						improveResultFactory.getCurrentProRecordOpsBuilder()
								.putAttribute(WeighHWANE16720Item.基本属性组_皮重, weighOther.getWeight())
								.putAttribute(WeighHWANE16720Item.基本属性组_毛重,BigDecimal.ZERO);

						//新6/30 散装 袋装判断
						Order order1=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.订单记录_ddjl)
								.getProConJunctionFactory().addEqual(OrderHWANE16677Item.基本属性组_单号, weighOther.getOrderNumber())
								.goBack().queryABean(Order.class,1);
						if(String.valueOf(CarbonEnumKeyValue.订单记录_类型_袋装_dz).equals(order1.getType())){
							integrationMsg=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.订单记录_ddjl,orderCode)
									.putAttribute(OrderHWANE16677Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_待过二磅_dgeb)
									.integrate();
						}else {
							integrationMsg=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.订单记录_ddjl,orderCode)
									.putAttribute(OrderHWANE16677Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_待过二磅_dgeb)
									.integrate();
						}
					}
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.SM.getCode())){
						improveResultFactory.getCurrentProRecordOpsBuilder()
								.putAttribute(WeighHWANE16720Item.基本属性组_皮重,BigDecimal.ZERO)
								.putAttribute(WeighHWANE16720Item.基本属性组_毛重, weighOther.getWeight());
						integrationMsg=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.供货订单_ghdd,orderCode)
								.putAttribute(SupplyOrderHWANE16829Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_待过二磅_dgeb)
								.integrate();
					}
					//修改 先毛后皮
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.PM.getCode())){
						improveResultFactory.getCurrentProRecordOpsBuilder()
								.putAttribute(WeighHWANE16720Item.基本属性组_皮重,BigDecimal.ZERO)
								.putAttribute(WeighHWANE16720Item.基本属性组_毛重, weighOther.getWeight());
						integrationMsg=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.倒料订单_dldd,orderCode)
								.putAttribute(PouringOrderHWANE18490Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_待过二磅_dgeb)
								.integrate();
					}
					log.info("修改订单信息结束,是否成功:{}",integrationMsg.success());
					if(!integrationMsg.success()){
						log.info("失败信息:{}",integrationMsg.getRefuse());
						PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_3);
						return false;
					}
					break;
				case 2:
					log.info("二次过磅触发:{}",orderCode);
					if(weighOther2 !=null){
						PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_1);
						return false;
					}
					if(weighOther1 ==null){
						PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_2);
						return false;
					}

					IntegrationMsg integrationMsg1=null;
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.OR.getCode())){
						log.info("开始修改订单信息:{}", weighOther.getOrderNumber());
						improveResultFactory.getCurrentProRecordOpsBuilder()
								.putAttribute(WeighHWANE16720Item.基本属性组_皮重,BigDecimal.ZERO)
								.putAttribute(WeighHWANE16720Item.基本属性组_毛重, weighOther.getWeight());
						BigDecimal newWight=PublicMethod.subtractBigDecimal(weighOther.getWeight(), weighOther1.getWeightTare(), PublicConstant.weightDecimals,null);
						integrationMsg1=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.订单记录_ddjl,orderCode)
								.putAttribute(OrderHWANE16677Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_待归还卡_dghk)
								.putAttribute(OrderHWANE16677Item.基本属性组_实际重量,newWight)
								.integrate();
					}
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.SM.getCode())){
						log.info("开始修改供货订单信息:{}", weighOther.getOrderNumber());
						improveResultFactory.getCurrentProRecordOpsBuilder()
								.putAttribute(WeighHWANE16720Item.基本属性组_皮重, weighOther.getWeight())
								.putAttribute(WeighHWANE16720Item.基本属性组_毛重,BigDecimal.ZERO);
						BigDecimal newWight=PublicMethod.subtractBigDecimal(weighOther1.getWeightGross(), weighOther.getWeight(), PublicConstant.weightDecimals,null);
						integrationMsg1=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.供货订单_ghdd,orderCode)
								.putAttribute(SupplyOrderHWANE16829Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_待归还卡_dghk)
								.putAttribute(SupplyOrderHWANE16829Item.基本属性组_实际重量,newWight)
								.integrate();
					}
					//修改 先毛后皮
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.PM.getCode())){
						log.info("开始修改倒料订单信息:{}", weighOther.getOrderNumber());
						improveResultFactory.getCurrentProRecordOpsBuilder()
								.putAttribute(WeighHWANE16720Item.基本属性组_皮重, weighOther.getWeight())
								.putAttribute(WeighHWANE16720Item.基本属性组_毛重,BigDecimal.ZERO);
						BigDecimal newWight=PublicMethod.subtractBigDecimal(weighOther1.getWeightGross(), weighOther.getWeight(), PublicConstant.weightDecimals,null);
						integrationMsg1=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.倒料订单_dldd,orderCode)
								.putAttribute(PouringOrderHWANE18490Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_已出厂_ycc)
								.putAttribute(PouringOrderHWANE18490Item.基本属性组_重量,newWight)
								.integrate();
//						pouringOrderHWANE18490BNB.saveNew(orderCode);
					}
					log.info("修改订单信息结束,是否成功:{}",integrationMsg1.success());
					if(!integrationMsg1.success()){
						log.info("失败信息:{}",integrationMsg1.getRefuse());
						PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_3);
						return false;
					}
					break;
			}
			return true;
		}else {
			PublicMethod.returnMessage(improveResultFactory, PublicReturn.ORDER_12);
			return false;
		}
	}

	private WeighOther getWeigh(String num, int sum){
		return CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.过磅信息_gbxx).getProConJunctionFactory()
				.addEqual(WeighHWANE16720Item.基本属性组_订单号,num)
				.addEqual(WeighHWANE16720Item.基本属性组_是否正常,true)
				.addEqual(WeighHWANE16720Item.基本属性组_过磅次数,sum).goBack().queryABean(WeighOther.class);
	}

	private boolean updateWeigh(WeighOther weighOther, ImproveResultFactory improveResultFactory){
		boolean flag=false;
		log.info("触发修改:{}", JSON.toJSON(weighOther));
		if(weighOther.getFrequency()!=null&& weighOther.getIsOk()){
			log.info("触发订单重量");
			WeighOther weighOther1 =null;
			WeighOther weighOther2 =null;
			if(weighOther.getFrequency()==2){
				weighOther1 =getWeigh(weighOther.getOrderNumber(),1);
				weighOther2 = weighOther;
			}
			if(weighOther.getFrequency()==1){
				weighOther1 = weighOther;
				weighOther2 =getWeigh(weighOther.getOrderNumber(),2);
			}
			if(weighOther1 !=null&& weighOther2 !=null){
				log.info("开始修订订单重量");
				IntegrationMsg integrationMsg=null;
				if(weighOther.getOrderNumber()!=null){
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.OR.getCode())){
						Order order=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.订单记录_ddjl).getProConJunctionFactory()
								.addEqual(OrderHWANE16677Item.基本属性组_单号, weighOther.getOrderNumber()).goBack().queryABean(Order.class);
						if(order!=null){
							if(String.valueOf(PublicConstant.OrderStateOver).equals(order.getState())
							||String.valueOf(CarbonEnumKeyValue.订单记录_状态_待归还卡_dghk).equals(order.getState())
							){
								PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_4);
								return true;
							}

							log.info("修改销售订单重量:{}", order.getRecordCode());
							integrationMsg=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.订单记录_ddjl,order.getRecordCode())
									.putAttribute(OrderHWANE16677Item.基本属性组_实际重量,PublicMethod.subtractBigDecimal(weighOther2.getWeightGross(), weighOther1.getWeightTare(),PublicConstant.weightDecimals,null))
									.integrate();
						}
					}
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.SM.getCode())){
						SupplyOrder order=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.供货订单_ghdd).getProConJunctionFactory()
								.addEqual(SupplyOrderHWANE16829Item.基本属性组_单号, weighOther.getOrderNumber()).goBack().queryABean(SupplyOrder.class);
						if(order!=null){
							if(String.valueOf(PublicConstant.OrderStateOver).equals(order.getState())){
								PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_4);
								return true;
							}
							log.info("修改供货订单重量:{}", order.getRecordCode());
							integrationMsg=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.供货订单_ghdd,order.getRecordCode())
									.putAttribute(SupplyOrderHWANE16829Item.基本属性组_实际重量,PublicMethod.subtractBigDecimal(weighOther1.getWeightGross(), weighOther2.getWeightTare(),PublicConstant.weightDecimals,null))
									.integrate();
						}
					}
					if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.PM.getCode())){
						PouringOrder order=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.倒料订单_dldd).getProConJunctionFactory()
								.addEqual(PouringOrderHWANE18490Item.基本属性组_单号, weighOther.getOrderNumber()).goBack().queryABean(PouringOrder.class);
						if(order!=null){
							if(String.valueOf(PublicConstant.OrderStateOver).equals(order.getState())){
								PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_4);
								return true;
							}
							log.info("修改倒料订单重量:{}", order.getRecordCode());
							integrationMsg=CarbonPanel.getFGRecordBuilder(CarbonBaseConstant.倒料订单_dldd,order.getRecordCode())
									.putAttribute(PouringOrderHWANE18490Item.基本属性组_重量,PublicMethod.subtractBigDecimal(weighOther2.getWeightGross(), weighOther1.getWeightTare(),PublicConstant.weightDecimals,null))
									.integrate();
						}
					}
				}
				if(integrationMsg!=null){
					log.info("修改订单信息结束,是否成功:{}",integrationMsg.success());
					if(!integrationMsg.success()){
						log.info("失败信息:{}",integrationMsg.getRefuseMsgContentStr());
						PublicMethod.returnMessage(improveResultFactory, integrationMsg.getRefuseMsgContentStr());
						return true;
					}
				}
			}
		}
		return flag;
	}

	@Override
	public boolean beforeRemove(FuncGroupContext funcGroupContext, RemoveRecordInfo removeRecordInfo, DeleteMessageFactory defDeleteMessageFactory) {
		Collection<String> list=removeRecordInfo.getRecordCodes();
		log.info("删除业务开始:{}",list);
		boolean isOk=true;
		if(list!=null){
			for (String x : list) {
				WeighOther weighOther =CarbonPanel.getRecordDiscover(CarbonBaseConstant.过磅信息_gbxx).getRecordBean(x, WeighOther.class);
				return VerifyActionable(weighOther,null,defDeleteMessageFactory);
			}
		}
		log.info("删除业务结束");
		return isOk;
	}

	/**
	 * 验证订单是否可操作
	 * @return
	 */
	private boolean VerifyActionable(WeighOther weighOther, ImproveResultFactory improveResultFactory, DeleteMessageFactory defDeleteMessageFactory){
		boolean isOk=true;
		if(weighOther !=null){
			Order order=null;
			SupplyOrder supplyOrder=null;
			PouringOrder pouringOrder=null;

			if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.OR.getCode())){
				order=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.订单记录_ddjl).getProConJunctionFactory()
						.addEqual(OrderHWANE16677Item.基本属性组_单号, weighOther.getOrderNumber())
						.addEqual(OrderHWANE16677Item.基本属性组_是否作废,CarbonEnumKeyValue.是否_否_f)
						.addEqual(OrderHWANE16677Item.基本属性组_是否退货,CarbonEnumKeyValue.是否_否_f)
						.addEqual(OrderHWANE16677Item.基本属性组_状态,PublicConstant.OrderStateOver)
						.goBack().queryABean(Order.class);
				if(order==null){
					order=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.订单记录_ddjl).getProConJunctionFactory()
							.addEqual(OrderHWANE16677Item.基本属性组_单号, weighOther.getOrderNumber())
							.addEqual(OrderHWANE16677Item.基本属性组_是否作废,CarbonEnumKeyValue.是否_否_f)
							.addEqual(OrderHWANE16677Item.基本属性组_是否退货,CarbonEnumKeyValue.是否_否_f)
							.addEqual(OrderHWANE16677Item.基本属性组_状态,CarbonEnumKeyValue.订单记录_状态_待归还卡_dghk)
							.goBack().queryABean(Order.class);
				}
			}
			if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.SM.getCode())){
				supplyOrder=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.供货订单_ghdd).getProConJunctionFactory()
						.addEqual(SupplyOrderHWANE16829Item.基本属性组_单号, weighOther.getOrderNumber())
						.addEqual(SupplyOrderHWANE16829Item.基本属性组_是否作废,CarbonEnumKeyValue.是否_否_f)
						.addEqual(SupplyOrderHWANE16829Item.基本属性组_是否退货,CarbonEnumKeyValue.是否_否_f)
						.addEqual(SupplyOrderHWANE16829Item.基本属性组_状态,PublicConstant.OrderStateOver)
						.goBack().queryABean(SupplyOrder.class);
			}
			if(weighOther.getOrderNumber().contains(PublicEnum.OrderHeader.PM.getCode())){
				pouringOrder=CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.倒料订单_dldd).getProConJunctionFactory()
						.addEqual(PouringOrderHWANE18490Item.基本属性组_单号, weighOther.getOrderNumber())
						.addEqual(PouringOrderHWANE18490Item.基本属性组_是否作废,false)
						.addEqual(PouringOrderHWANE18490Item.基本属性组_状态,PublicConstant.OrderStateOver)
						.goBack().queryABean(PouringOrder.class);
			}

			if(order!=null||supplyOrder!=null||pouringOrder!=null){
				if(improveResultFactory!=null){
					PublicMethod.returnMessage(improveResultFactory, PublicReturn.Weight_4);
				}else {
					PublicMethod.returnMessage(defDeleteMessageFactory, PublicReturn.Weight_4);
				}
				isOk=false;
			}
		}
		return isOk;
	}
}
